package com.ruoyi.resume.utils.deepseek;



import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

@Deprecated
public class DeepSeek {

    // 调用Flask API接口
    public static String chatWithAPI(String messageContent) throws Exception {
        // Flask接口URL
        String url = "http://59.77.5.2:12345/api/chat"; // 根据实际地址调整
        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();

        // 设置请求方法为 POST
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setDoOutput(true);

        // 创建JSON请求体
        String jsonInputString = "{\"message\": \"" + messageContent + "\"}";

        // 发送请求
        try (OutputStream os = connection.getOutputStream()) {
            byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
            os.write(input, 0, input.length);
        }

        // 读取响应
        try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
            StringBuilder response = new StringBuilder();
            String responseLine;
            while ((responseLine = br.readLine()) != null) {
                response.append(responseLine.trim());
            }
            return response.toString();
        }
    }

    // 测试主函数
    public static void main(String[] args) {
        try {
            String messageContent = "为什么天空是蓝色的？";
            String response = chatWithAPI(messageContent);
            System.out.println("API响应: " + response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
